<?php
namespace app\applet\controller;

use app\applet\model\TenantManagement;
use think\Controller;
use think\Request;
use think\Validate;

class TenantManage extends Controller {
    public function __construct(Request $request = null)
    {
//        parent::__construct($request);
    }

    /**
     * 待办事项
     */
    public function Todo() {

    }

    /**
     * 员工端租客列表
     */
    public function tenantList(){
        $model=new TenantManagement();
        $date=$model->templateList();
        if($date){
            returnJson(200,"成功",$date)->send();die;
        }else{
            returnJson(-412,"失败")->send();die;
        }
    }
    /**
     * 员工端租客詳情
     */
    public function tenantDetails(){
        $model=new TenantManagement();
        $date=$model->tenantDetails();
        if($date){
            returnJson(200,"成功",$date)->send();die;
        }else{
            returnJson(-412,"失败")->send();die;
        }
    }
    /**
     * 添加租客手机号
     */
    public function tenantPhone(){
        $model=new TenantManagement();
        $input=input();
        $phone= trim( $input['phone'] );
        $id= trim( $input['id'] );
        $date=$model->tenantPhone($phone,$id);
        if($date){
            returnJson(-412,"手机号已存在")->send();die;
        }else{
            returnJson(200)->send();die;
        }
    }
    /**
     * 添加租客手机号
     */
    public function tenantAdd(){
        $model=new TenantManagement();
        $input=input();
        $validate = new Validate([
            ['tenant_tel', 'require|max:11|/^1[3-8]{1}[0-9]{9}$/', '手机号不能为空|手机号长度必须是11位|手机号格式不正确'],
            ['tenant_front', 'require', '身份证正面不能为空'],
            ['tenant_back', 'require', '身份证反面不能为空'],

        ]);
        if(!$validate->check($input))
        {
            returnJson(-1001,  $validate->getError())->send();die;
        }
        $date=$model->tenantAdd($input);
        if($date==2){
            returnJson(-412,"身份证正面图片拍摄不清晰")->send();die;
        } elseif($date==3){
            returnJson(-412,"身份证反面图片拍摄不清晰")->send();die;
        }elseif($date==4){
            returnJson(-412,"租客已存在")->send();die;
        }else{
            returnJson(200,"成功")->send();die;
        }
    }
}